#coding=utf8
import sys, os
import time
from threading import Timer
from common_utils import *

__strCurrentDir__ = os.path.abspath(os.path.dirname(__file__))
__strModuleDir__ = os.path.dirname(__strCurrentDir__)

OUTTIME_FILE_SECONDS = 3600 * 24

OUT_PUT_IMGS_PATH = "static/"

def _clean_imgs_():
   for root, dir, files in os.walk(OUT_PUT_IMGS_PATH):
      for file in files:
         logger.warning(file)
         if ".js" in file:
            continue 

         full_path = os.path.join(root, file)
         mtime = os.stat(full_path).st_mtime
         nowS = time.time()
         if nowS - mtime > OUTTIME_FILE_SECONDS:
            os.remove(full_path)
   return

def clear_outime_files_task():
    logger.warn("start clear invalid files start...")

    _clean_imgs_()
   #  _clean_videos_()
   #  _clean_monitor_file_()
    #_clean_graio_tmp_file_()

    logger.warn(f"finish clear invalid files finished...")

t = RepeatingTimer(5*60.0 * 1, clear_outime_files_task)
t.start()